package test03;

/**
 * 计算进度的线程 - 守护线程
 *
 * @author V
 * @date 2025-03-10
 */
public class ProgressThread extends Thread {

    /**
     * 拷贝文件的状态
     */
    private FileData fileData;

    public ProgressThread() {

    }

    public ProgressThread(FileData fileData) {
        this.fileData = fileData;
    }

    @Override
    public void run() {

        while (true) {
            // System.out.println(this.fileData.getCopiedSize() + "-" + this.fileData.getTotalSize());

            if(this.fileData.getTotalSize() == 0){
                continue;
            }

            double percent = this.fileData.getCopiedSize() * 1.0 / this.fileData.getTotalSize() * 100;
            System.out.printf("完成进度：%.2f %% %n",percent);

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }


    }
}